package logic

import (
	"context"
	"house/models/mysql"

	"house/houserpc/houserpc"
	"house/houserpc/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type GetHouseLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewGetHouseLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetHouseLogic {
	return &GetHouseLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *GetHouseLogic) GetHouse(in *houserpc.GetHouseRequest) (*houserpc.GetHouseResponse, error) {
	// todo: add your logic here and delete this line

	var house mysql.House
	mysql.DB.Where("id=?", in.Id).Find(&house)
	return &houserpc.GetHouseResponse{
		Titls: house.Title,
		Types: house.Types,
		Ads:   house.Ads,
		Price: float32(house.Price),
		Id:    int64(house.ID),
	}, nil
}
